package com.yudaxian.mq.config;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: yudaxian
 * @Description: TODO
 * @DateTime: 2024/9/12 23:51
 **/
//@Configuration
//@Slf4j
//public class RabbitConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
//
//    @Resource
//    private RabbitTemplate rabbitTemplate;
//
////    @PostConstruct
////    public void initRabbitTemplate() {
////        rabbitTemplate.setConfirmCallback(this);
////        rabbitTemplate.setReturnsCallback(this);
////    }
////
////    @Override
////    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
////        // 消息发送到交换机成功或失败
////        log.info("消息发送到交换机成功");
////        log.info("confirm 发送到交换机的回调：correlationData:{},ack:{},cause:{}", correlationData, ack, cause);
////    }
//
//    @Override
//    public void returnedMessage(ReturnedMessage returned) {
//        // 消息发送到队列失败才会调用此方法
//        log.info("ReturnedMessage 消息主体: " + new String(returned.getMessage().getBody()));
//        log.info("ReturnedMessage 应答码: " + returned.getReplyCode());
//        log.info("ReturnedMessage 描述：" + returned.getReplyText());
//        log.info("ReturnedMessage 消息使用的交换器 exchange : " + returned.getExchange());
//        log.info("ReturnedMessage 消息使用的路由键 routing : " + returned.getRoutingKey());
//    }
//}
